


#include <iostream>
using namespace std;


//#include <string>
//int main()
//{
//	string s("abc123034");
//	for (auto ch : s)
//	{
//		int i = isdigit(ch);
//		
//		cout << i << "	" << ch << endl;
//	}
//
//	return 0;
//}



int findLHS(int* nums, int numsSize)
{
    if (1 == numsSize)
        return 0;

    int min = nums[0], max = nums[0];
    for (int i = 1; i < numsSize; ++i)
    {
        if (nums[i] < min)
            min = nums[i];

        if (nums[i] > max)
            max = nums[i];
    }

    int* cnt = (int*)calloc(max - min + 1, sizeof(*cnt));
    for (int i = 0; i < numsSize; ++i)
    {
        cnt[nums[i] - min]++;
    }

    int ans = 0;
    for (int i = 0; i < max - min + 1 - 1; ++i)
    {
        if (cnt[i] && cnt[i + 1])
        {
            if (cnt[i] + cnt[i + 1] > ans)
                ans = cnt[i] + cnt[i + 1];
        }
    }

    return ans;
}


int findLHS2(int* nums, int numsSize)
{
    if (1 == numsSize)
        return 0;

    int min = nums[0], max = nums[0];
    for (int i = 1; i < numsSize; ++i)
    {
        if (min > nums[i])
        {
            min = nums[i];
        }

        if (max < nums[i])
        {
            max = nums[i];
        }
    }
    //printf("max %d:min %d", max, min);
    //int cnt[max - min + 1];
    int cnt[39018456 - (-48486071) + 1];
    for (int i = 0; i < max - min + 1; ++i)
    {
        cnt[i] = 0;
    }

    for (int i = 0; i < numsSize; ++i)
    {
        //printf("%d", nums[i]);
        cnt[nums[i] - min]++;
    }

    int ans = 0;
    for (int i = 0; i < numsSize - 1; ++i)
    {
        int tmp = 0;
        for (int j = i + 1; j < numsSize; ++j)
        {
            if (nums[i] + 1 == nums[j] || nums[i] - 1 == nums[j])
            {
                tmp = cnt[nums[i] - min] + cnt[nums[j] - min];

                if (tmp > ans)
                    ans = tmp;
            }
        }
    }

    return ans;
}

int main()
{
    int a[] = { -48486071, -48020198, -34365978, -14276942, 19133069, -24101833, 9961393, 39018456, -21824989, 6478042 };
    cout << findLHS(a, sizeof(a) / sizeof(a[0])) << findLHS2(a, sizeof(a) / sizeof(a[0])) << endl;

    return 0;
}